﻿using System.Text.RegularExpressions;

namespace AbstractBugTracker
{
    internal static class BugRefUtils
    {
        /// <summary>
        /// lambda re-write
        /// </summary>
        private static readonly Regex s_MethodTypeNameRegex1 = new Regex("^(.+?)(/<>c__DisplayClass[0-9a-f]+(`[0-9]+)?)+$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

        /// <summary>
        /// enumerator re-write
        /// </summary>
        private static readonly Regex s_MethodTypeNameRegex2 = new Regex("^(.+)<(.+)>d__[0-9a-f]+$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

        internal static string MapMethodTypeName(string methodTypeName)
        {
            string ret = s_MethodTypeNameRegex1.Replace(methodTypeName, "$1");
            ret = s_MethodTypeNameRegex2.Replace(ret, "$1$2");
            return ret;
        }


        /// <summary>
        /// lambda re-write
        /// </summary>
        private static readonly Regex s_MethodNameRegex = new Regex("^(.+)<(.+)>b__[0-9a-f]+(.+)$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

        internal static string MapMethodName(string methodName)
        {
            string ret = s_MethodNameRegex.Replace(methodName, "$1$2$3");
            return ret;
        }
    }
}
